package com.marion.ddd.enums;

import lombok.Getter;

import java.util.Optional;

public enum OverdraftPolicy {
    /**
     * 0 - 不可以扣成负数
     * 1 - 可以为负数
     */
    NEVER(0),
    ALLOW(1);

    @Getter
    private final int value;

    OverdraftPolicy(int value) {
        this.value = value;
    }

    public static Optional<OverdraftPolicy> fromValue(int value) {
        for (OverdraftPolicy policy : OverdraftPolicy.values()) {
            if (policy.getValue() == value) {
                return Optional.of(policy);
            }
        }
        return Optional.empty();
    }
}
